package com.ship.dispatch.bean;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.ship.dispatch.util.NumberFormatUtil.decimalFormat;

/**
 *@title SpDispatchSchemeExecute
 *@description
 *@author yl
 *@create 2023/12/13 0013
 */
@Data
@TableName("sp_dispatch_scheme_execute")
public class SpDispatchSchemeExecute extends BaseBean implements Joinable {

    /**
     * 方案ID
     */
    @Label(value = "方案ID")
    private Long schemeId;
    @Label(value = "执行方案ID")
    private Long schemeDetailId;

    /**
     * 方案编号
     */
    @Label(value = "方案编号")
    private Integer schemeNumber;

    /**
     * 航次号
     */
    @Label(value = "航次号")
    @TableColumn
    private String voyageNo;

    /**
     * 货号
     */
    @Label(value = "货号")
    @TableColumn
    private String goodsNum;

    /**
     * 装载港id
     */
    @TableColumn
    private Long expectedLoadingPortId;

    /**
     * 卸载港id
     */
    @TableColumn
    private Long expectedUnloadingPortId;

    /**
     * 资源合同ID
     */
//    @Label(value = "资源合同ID")
//    @TableColumn
    private Long resourceContract;

    /**
     * 资源合同名称
     */
    @Label(value = "资源合同·采购")
    @TableColumn
    private String contractName;

    /**
     * 资源方（资源合同中的卖方）
     */
    @Label(value = "资源方")
    @SearchItem
    @TableColumn
    private String seller;

    /**
     * 贸易类型(资源合同中的贸易类型  1：长协，2：中期，3：现货）
     */
    @Label(value="贸易类型·采购",enumContent = "贸易类型",multiSelect = true)
    private Integer tradeType;

    @Label(value="贸易类型·采购")
    @TableColumn
    @TableField(exist = false)
    private String tradeTypeStr;

    /**
     * 贸易主体 1：国贸，2：新贸
     */
    @Label(value="贸易主体·采购",enumContent = "贸易主体",multiSelect = true)
    private Integer tradeBody;

    @Label(value="贸易主体·采购")
    @TableColumn
    @TableField(exist = false)
    private String tradeBodyStr;

    /**
     * 贸易类型(销售）
     */
    @Label(value="贸易类型(销售）",enumContent = "贸易类型(销售）",multiSelect = true)
    private Integer sellerTradeType;

    @Label(value="贸易类型·销售")
    @TableField(exist = false)
    @TableColumn
    private String sellerTradeTypeStr;

    /**
     * 贸易主体(销售）
     */
    @Label(value="贸易主体·销售",enumContent = "贸易主体(销售）",multiSelect = true)
    private Integer sellerTradeBody;

    @Label(value="贸易主体·销售")
    @TableColumn
    @TableField(exist = false)
    private String sellerTradeBodyStr;

    /**
     * 合同装载量单位(1:MMBtu,2:m³,3:MT)
     */
    private Integer loadingCapacityUnit;

    /**
     * 舱容（单位：立方米）
     */
    private BigDecimal storageCapacity;

    /**
     * 舱容（单位：立方米）
     */
    @Label(value = "舱容")
    @TableColumn
    @TableField(exist = false)
    private String storageCapacityString;

    public String getStorageCapacityString(){
        String result = null;
        if (getStorageCapacity()!=null){
            result = decimalFormat.format(getStorageCapacity());
            result = result+" m³";}
        return result;
    }

    /**
     * 实际卸载时间
     */
    @Label(value = "实际卸载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date realityUnloadingDate;

    /**
     * 实际装载时间
     */
    @Label(value = "实际装载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date realityLoadingDate;

    /**
     * 实际卸载量
     */
    @Label(value = "实际卸载量")
    @TableColumn
    private BigDecimal realityUnloadingCapacity;

    /**
     * 实际装载量
     */
    @Label(value = "实际装载量")
    @TableColumn
    private BigDecimal realityLoadingCapacity;

    /**
     * 预计装载时间
     */
    @Label(value = "预计装载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedLoadingDate;

    /**
     * 预计装载完成窗口
     */
    @Label(value = "预计装载完成窗口")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedLoadingCompletionWindow;

    /**
     * 预计装载港
     */
    @Label(value = "装载港")
    @TableColumn
    @SearchItem
    private String expectedLoadingPort;

    /**
     * 船名
     */
    @Label(value = "船舶名称")
    @TableColumn
    @SearchItem
    private String shipName;

    /**
     * IMO
     */
    @Label(value = "IMO")
    @TableColumn
    @SearchItem
    private String imo;

    /**
     * 巴拿马运河预定时间
     */
    @Label(value = "巴拿马运河预定时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date panamaCanalReservationDate;

    /**
     * 换港时间1
     */
    @Label(value = "换港时间1")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date portChangeDateOne;

    /**
     * 换港时间2
     */
    @Label(value = "换港时间2")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date portChangeDateTwo;

    /**
     * 换船时间1
     */
    @Label(value = "换船时间1")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date shipChangeDateOne;

    /**
     * 换船时间2
     */
    @Label(value = "换船时间2")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date shipChangeDateTwo;

    /**
     * 合同装载量
     */
    @Label(value = "合同装载量")
    @TableColumn
    private BigDecimal loadingCapacity;

    /**
     * 预计卸载港
     */
    @Label(value = "卸载港")
    @TableColumn
    private String expectedUnloadingPort;

    /**
     * 预计卸载窗口
     */
    @Label(value = "预计卸载时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedUnloadingWindow;

    /**
     * 印度预计卸载窗口
     */
    @Label(value = "印度预计卸载窗口")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date indiaUnloadTime;

    /**
     * 欧洲预计卸载窗口
     */
    @Label(value = "欧洲预计卸载窗口")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date europeUnloadTime;

    /**
     * 预计满载航程天数
     */
    @Label(value = "预计满载航程天数")
    @TableColumn
    private Integer expectedFullLoadVoyageDays;

    /**
     * 预计卸载完成窗口
     */
    @Label(value = "预计卸载完成时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedUnloadingCompletionWindow;

    /**
     * 预计空载航程天数
     */
    @Label(value = "预计空载航程天数")
    @TableColumn
    private Integer expectedEmptyLoadVoyageDays;

    /**
     * 预计空载返程窗口
     */
    @Label(value = "预计空载返程时间")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedEmptyReturnWindow;

    /**
     * 船速（节）
     */
    private BigDecimal shipSpeed;

    /**
     * 货量单位
     */
    @Label(value = "货量单位",enumContent = "装卸载量单位",multiSelect = true)
    private Integer quantityUnit;

    /**
     * 单个船装载货量
     */
    private BigDecimal singleGoodsQuantity;

    /**
     * 油耗
     */
    private BigDecimal oilConsumption;

    /**
     * 航线
     */
    private String shipRoute;

    /**
     * 航运合同名称
     */
    private String shipContractName;

    /**
     * 航运合同贸易主体(国贸、新贸)
     */
    @Label(value="贸易主体·船舶",enumContent = "贸易主体·船舶")
    @TableColumn
    private Integer shipTradeBody;

    @Label(value="贸易主体·船舶",enumContent = "贸易主体·船舶")
    @TableColumn
    @TableField(exist = false)
    private String shipTradeBodyStr;

    @TableField(exist = false)
    private String shipTradeBodyListForSearch;
    /**
     * 印度空载航程天数
     */
    private Integer indiaEmptyLoadDays;

    /**
     * 欧洲空载航程天数
     */
    private Integer europeEmptyLoadDays;

    /**
     * 船运合同id
     */
    private Long shipContractId;

    /**
     * 船运执行完成时间（月度时间）
     */
    @TableField(exist = false)
    private String finishTimeMonth;

    /**
     * 计划id
     */
    @Label(value = "计划id")
    private Long planId;

    /**
     * 船运合同类型（租入长期船、租入短期船、船舶租出、内部转租）
     */
    @Label(value="船运合同类型",enumContent = "船运合同类型",multiSelect = true)
    @TableColumn
    private Integer shipContractType;

    @Label(value="船运合同类型",enumContent = "船运合同类型",multiSelect = true)
    @TableField(exist = false)
    @TableColumn
    private String shipContractTypeStr;

    @TableField(exist = false)
    private String shipContractTypeListForSearch;

    /**
     * 审批，1：未审批，2：已审批
     */
    private Integer schemeApprove;

    /**
     * 上一次的更新的方案详情ID
     */
    private Long lastDetailId;

    /**
     * 时间
     */
    @TableField(exist = false)
    private Integer days;

    /**
     * 运费
     */
    @TableField(exist = false)
    private BigDecimal freight;

    /**
     * 贸易利润率
     */
    @TableField(exist = false)
    private BigDecimal trade;

    /**
     * 船舶利用率
     */
    @TableField(exist = false)
    private BigDecimal ship;

    /**
     * 装载量格式化
     */
    @TableField(exist = false)
    private String singleGoodsQuantityString;

    /**
     * 油耗格式化
     */
    @TableField(exist = false)
    private String oilConsumptionString;

    /**
     * 舱容格式化
     */
    @TableField(exist = false)
    @Label(value = "合同装载量")
    private String loadingCapacityString;

    /**
     * 资源类型（1：现货，2：潜在投标）
     */
    private Integer isPotential;

    /**
     * 资源合同ID（销售）
     */
    private Long sellerResourceContract;

    /**
     * 资源合同名称（销售）
     */
    @Label(value = "资源合同·销售")
    @TableColumn
    private String sellerContractName;

    /**
     * 资源合同名称（销售）
     */
    private Integer executeStatus;

    /**
     * 方案执行状态（0：未下发，1：已下发（船货排布），2：已排布（执行中），3：已完成，4：已终止）
     */
    private Integer planYear;

    /**
     * 买家
     */

    @Label(value = "买方")
    @SearchItem
    @TableColumn
    private String buyer;

    /**
     * 租出时间，多条
     */
    @TableField(exist = false)
    private List<String> leaseTermStrs = new ArrayList<>();
    /**
     * 货运标识
     */
    @TableField(exist = false)
    private String cargoCode;

//    @Label(value = "流程实例id")
//    @TableColumn
    private String processInstanceId;
    @Label(value = "状态",enumContent = "船运执行状态",multiSelect = true)
//    @TableColumn
    @SearchItem
    private Integer status;
    @TableField(exist = false)
    private String statusListForSearch;
    @Label(value = "流程执行人")
    @TableColumn
    private String assigeners;
    @Label(value = "船货排布id")
    @TableColumn
    private Long arrangeSchemeDetailId;

    /**
     * 上传发票时间-卸载港船代尾款
     */
    @Label(value = "上传发票时间-卸载港船代尾款")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date uploadInvoiceTime;

    /**
     * 上传发票时间节点类型（2：装载港船代尾款，4：卸载港船代尾款）
     */
    @Label(value = "上传发票时间节点类型（2：装载港船代尾款，4：卸载港船代尾款）")
    @TableColumn
    private Integer uploadInvoiceTimeNode;

    /**
     * 上传发票时间-装载港船代尾款
     */
    @Label(value = "上传发票时间-装载港船代尾款")
    @TableColumn
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date loadInvoiceTime;

    @Label(value = "合同卸载量")
    @TableColumn
    private BigDecimal contractUnloadingCapacity;
    /**
     *备注
     */
    @Label(value = "备注")
    @TableColumn
    private String remark;
    @Label(value = "完成时间")
    @TableColumn
    private Date finishTime;

    @ApiModelProperty(value = "方案下发时间")
    private Date schemeDeliveryTime;
    @Label(value="状态",enumContent = "状态",multiSelect = true)
    @TableField(exist = false)
    @TableColumn
    private String statusStr;
    public String getStatusStr(){
        String result = null;
        if (getStatus()!=null){
            Integer type = getStatus();
            if(type==0){
                result="进行中";
            }
            if (type == 1){
                result = "完成";
            }
            if (type == 2 || type==-1){
                result = "已终止";
            }
        }
        return result;
    }
    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }

    public String getShipContractTypeStr(){
        String result = null;
        if (getShipContractType()!=null){
            Integer type = getShipContractType();
            if (type == 1){
                result = "租入长期船";
            }
            if (type == 2){
                result = "租入短期船";
            }
            if (type == 3){
                result = "船舶租出";
            }
            if (type == 4){
                result = "内部转租";
            }
        }
        return result;
    }

    public String getShipTradeBodyStr(){
        String result = null;
        if (getShipTradeBody()!=null){
            Integer type = getShipTradeBody();
            if (type == 1){
                result = "国贸";
            }
            if (type == 2){
                result = "新贸";
            }
        }
        return result;
    }




    public String getTradeTypeStr(){
        String result = null;
        if (getTradeType()!=null){
            Integer type = getTradeType();
            if (type == 1){
                result = "长协";
            }
            if (type == 2){
                result = "中期";
            }
            if (type == 3){
                result = "现货";
            }
        }
        return result;
    }

    public String getTradeBodyStr(){
        String result = null;
        if (getTradeBody()!=null){
            Integer type = getTradeBody();
            if (type == 1){
                result = "国贸";
            }
            if (type == 2){
                result = "新贸";
            }
        }
        return result;
    }

    public String getSellerTradeTypeStr(){
        String result = null;
        if (getSellerTradeType()!=null){
            Integer type = getSellerTradeType();
            if (type == 1){
                result = "长协";
            }
            if (type == 2){
                result = "中期";
            }
            if (type == 3){
                result = "现货";
            }
        }
        return result;
    }

    public String getSellerTradeBodyStr(){
        String result = null;
        if (getSellerTradeBody()!=null){
            Integer type = getSellerTradeBody();
            if (type == 1){
                result = "国贸";
            }
            if (type == 2){
                result = "新贸";
            }
        }
        return result;
    }

    public String getLoadingCapacityString(){
        String result = null;
        if (getLoadingCapacity()!=null){
            result = decimalFormat.format(getLoadingCapacity());
            if(getLoadingCapacityUnit() != null){
                result = (result + (getLoadingCapacityUnit().intValue() == 1 ? " MMBtu"
                        : (getLoadingCapacityUnit().intValue() == 2 ? " m³" : " MT")));
            }
        }
        return result;
    }
}
